package ch02.Jianda;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Jianda4 {
    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read(new File("src/ch02/scores.xml"));

        Element element = document.getRootElement();

        List student = element.elements("student");
        for (int i = 0; i < student.size(); i++) {
            Element element1 = (Element) student.get(i);
            String id = element1.attribute("id").getText();
            System.out.println("id:"+id);
            List elements = element1.elements();
            for (int i1 = 0; i1 < elements.size(); i1++) {
                Element element2 = (Element) elements.get(i1);
                String text = element2.getText();
                System.out.println("\t"+text);
            }
        }
    }
}
